<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>生成器函数参数</title>
</head>

<body>

  <script>
    function* gen(arg) {
      console.log(arg);
      let one = yield 111;
      console.log(one);
      let two = yield 222;
      console.log(two);
      let three = yield 333;
      console.log(three);
    }

    // 执行获取迭代器对象
    let iterator = gen('AAA');
    console.log(iterator.next()); // 'AAA'
    // next方法可以传入实参
    console.log(iterator.next('BBB')); // 传入参数作为第一个 yield 的返回值
    console.log(iterator.next('CCC')); // 传入参数作为第二个 yield 的返回值
    console.log(iterator.next('DDD')); // 传入参数作为第三个 yield 的返回值
  </script>
</body>

</html>